Public Class frmSystemLogFilter
    Public sqlDK As String = ""
    Private Sub frmSystemLogFilter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitSearchControls()
    End Sub

    Private Sub btnLoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoc.Click
        Me.Close()
    End Sub

    Private Sub InitSearchControls()
        Dim query = CActions.GetActionList()
        cmbAction.ValueMember = "ID_Action"
        cmbAction.DisplayMember = "ActionName"
        cmbAction.DataSource = query
    End Sub

    Public Function PopulateDK() As String
        If cmbAction.SelectedValue IsNot Nothing And cmbAction.Enabled Then
            sqlDK = String.Format(" Id_Action = {0}", cmbAction.SelectedValue)
        End If

        If txtUser.Text <> "" Then
            If Len(mySqlDK) > 0 Then
                sqlDK += " and "
            End If
            sqlDK += String.Format("Id_User in (select User_ID from tblUser where loginname like N'%{0}%')", txtUser.Text)
        End If

        If txtLogContent.Text <> "" Then
            If Len(mySqlDK) > 0 Then
                sqlDK += " and "
            End If
            sqlDK += String.Format("LogContent like N'%{0}%'", txtLogContent.Text)
        End If

        If dtFromDate.Enabled Then
            If Len(mySqlDK) > 0 Then
                sqlDK += " and "
            End If
            sqlDK += String.Format("LogDate >= '{0}' and LogDate <= '{1}'", dtFromDate.Value, dtToDate.Value)
        End If
        Return sqlDK
    End Function

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        sqlDK = ""
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub chkDate_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDate.CheckedChanged
        dtFromDate.Enabled = chkDate.Checked
        dtToDate.Enabled = chkDate.Checked
    End Sub

    Private Sub chkAction_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAction.CheckedChanged
        cmbAction.Enabled = chkAction.Checked
    End Sub
End Class